<?php

namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class WithdrawUser extends Model
{
    protected $table = 'withdraw_user';
    public  $timestamps = false;
    protected $primaryKey= 'withdraw_user_id';

    /**
     * 添加一个提现账号
     * @param array $data
     * @return bool
     */
    public function addWithdrawUserItem(array $data)
    {
        $data = [
            "client_id"=> "1",
            "name"=> "carey",
            "mobile"=> "13071297155",
            "bank_name"=> '支付宝',
            "account"=> '13071297155',
            "nickname"=> "carey@carey.cn"
        ];
        $this->client_id = $data['client_id'];
        $this->name = $data['name'];
        $this->mobile = $data['mobile'];
        $this->bank_name = $data['bank_name'];
        $this->account = $data['account'];
        $this->nickname = $data['nickname'];
        if ($this->save()){
            return $this->toArray();
        }
        return false;
    }

    /**
     * 编辑一个提现账号
     * @access public
     * @param array $data 外部数据
     * @return array|false
     */
    public function setWithdrawUserItem(array $data)
    {
        $ds = [
            "withdraw_user_id"=> "4",
            "client_id"=> "1",
            "name"=> "carey",
            "mobile"=> "13071297155",
            "bank_name"=> '支付宝',
            "account"=> '13071297155',
            "nickname"=> "carey@carey.cn"
        ];
        $res = withdraw_user::where('withdraw_user_id',4)->update($ds);
        if ($res){
            return true;
        }
        return false;
    }


    /**
     * 批量删除提现账号
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function delWithdrawUserList(array $data)
    {
        $withdraw_user_id = [3,4];
        $res = withdraw_user::where('withdraw_user_id','$withdraw_user_id')->delete();
        if ($res){
            return $res;
        }

    }


    /**
     * 获取指定账号的一个提现账号
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function getWithdrawUserItem(array $data)
    {

        $res = withdraw_user::where('withdraw_user_id',4)->first()->toArray();
        if ($res){
            return $res;
        }

    }


    /**
     * 获取指定账号的提现账号列表
     * @access public
     * @param array $data 外部数据
     * @return array|false
     * @throws
     */
    public function getWithdrawUserList(array $data)
    {
        // 实际查询
        $res = withdraw_user::select()->limit('10');

        return json_encode($res);
    }



}
